<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>优惠卷管理</title>
</head>
<link rel="stylesheet" href="../static/layeropen.css">
<link rel="stylesheet" href="../static/layui_ext/dtree/dtree.css">
<link rel="stylesheet" href="../static/layui_ext/dtree/font/dtreefont.css">
<script src="../static/global.js"></script>
<script src="../static/layui_ext/dtree/dtree.js"></script>
<body>

<form style="margin-top: 20px" class="layui-form layui-form-pane">
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">优惠卷名字</label>
            <div class="layui-input-block">
                <input type="text" name="coupon_name" id="coupon_name_sousou" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <div class="layui-input-inline">
                <button type="button" class="layui-btn" id="couponSusuo" lay-filter="couponSusuo">搜索</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </div>
</form>
<!--优惠卷头部工具栏-->
<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" lay-event="add">添加</button>
        <button class="layui-btn layui-btn-sm" lay-event="delete">删除</button>
        <button class="layui-btn layui-btn-sm" lay-event="update">编辑</button>
    </div>
</script>
<!--渲染优惠卷表格-->
<table class="layui-hide" id="coupondemo" lay-filter="coupontest"></table>
<!--优惠卷行内监听工具栏-->
<script type="text/html" id="barDemo">
    <button class="layui-btn layui-btn-xs" id="coupon_category_relation" lay-event="coupon_category_relation">关联分类
    </button>
    <a class="layui-btn layui-btn-xs" lay-event="detail">查看</a>
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
<!--优惠卷的修改From表单-->
<div style="display: none" id="couponDiv">
    <form style="margin-top: 20px;margin-left: 30px" id="couponUpForm" lay-filter="couponUpForm"
          class="layui-form layui-form-pane" action="">
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">优惠卷选择类型</label>
                <div class="layui-inline kuang">
                    <select name="coupon_type" lay-filter="coupon_type">
                        <option value="">请选择</option>
                        <option value="0">全场赠券</option>
                        <option value="1">会员赠券</option>
                        <option value="2">购物赠券</option>
                        <option value="3">注册赠券</option>
                    </select>
                </div>
            </div>

            <div class="layui-inline">
                <label class="layui-form-label">发布状态</label>
                <div class="layui-inline kuang">
                    <select name="publish" lay-filter="publish">
                        <option value="">请选择</option>
                        <option value="0">未发布</option>
                        <option value="1">已发布</option>
                    </select>
                </div>
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">优惠卷名字</label>
                <div class="layui-input-block">
                    <input type="text" name="coupon_name" autocomplete="off" class="layui-input">
                    <input type="text" name="id" class="layui-input layui-hide">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">数量</label>
                <div class="layui-input-inline">
                    <input type="number" name="num" min="0" step="1" autocomplete="off" class="layui-input"
                           data-prec="4">
                </div>
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">金额</label>
                <div class="layui-input-block">
                    <input class="layui-input layui-input-number" name="amount" id="amount" min="0" max="100" step="1"
                           data-prec="4">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">限领张数</label>
                <div class="layui-input-inline">
                    <input type="number" name="per_limit" autocomplete="off" class="layui-input">
                </div>
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">使用类型</label>
                <div class="layui-inline kuang">
                    <select name="use_type" lay-filter="use_type ">
                        <option value="">请选择</option>
                        <option value="0">全场通用</option>
                        <option value="1">指定分类</option>
                        <option value="2">指定商品</option>
                    </select>
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">使用门槛</label>
                <div class="layui-input-block">
                    <input class="layui-input layui-input-number" name="min_point" id="min_point" min="0" max="100"
                           step="1" data-prec="4">
                </div>
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">开始时间</label>
                <div class="layui-input-block">
                    <input type="text" name="start_time" id="start_time" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">结束时间</label>
                <div class="layui-input-inline">
                    <input type="text" name="end_time" id="end_time" autocomplete="off" class="layui-input">
                </div>
            </div>
        </div>


        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">领取会员等级</label>
                <div class="layui-inline kuang">
                    <select name="member_level" lay-filter="member_level">
                        <option value="">请选择</option>
                        <option value="0">不限等级</option>
                        <option value="1">对应等级</option>
                    </select>
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">发行数量</label>
                <div class="layui-input-inline">
                    <input type="number" name="publish_count" autocomplete="off" class="layui-input">
                </div>
            </div>
        </div>

        <!--        <div class="layui-form-item">-->
        <!--            <div class="layui-inline">-->
        <!--                <label class="layui-form-label">已使用数量</label>-->
        <!--                <div class="layui-input-block">-->
        <!--                    <input type="number" name="use_count" autocomplete="off" class="layui-input">-->
        <!--                </div>-->
        <!--            </div>-->
        <!--            <div class="layui-inline">-->
        <!--                <label class="layui-form-label">领取数量</label>-->
        <!--                <div class="layui-input-inline">-->
        <!--                    <input type="number" name="receive_count" autocomplete="off" class="layui-input">-->
        <!--                </div>-->
        <!--            </div>-->
        <!--        </div>-->

        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">领取开始日期</label>
                <div class="layui-input-block">
                    <input type="text" name="enable_start_time" id="enable_start_time" autocomplete="off"
                           class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">领取结束日期</label>
                <div class="layui-input-inline">
                    <input type="text" name="enable_end_time" id="enable_end_time" autocomplete="off"
                           class="layui-input">
                </div>
            </div>
        </div>


        <div class="layui-inline">
            <div class="layui-inline">
                <label class="layui-form-label">优惠卷图片</label>
                <div class="layui-input-inline">
                    <div class="layui-upload">
                        <img style="width: 80px;height: 80px" class="layui-upload-img layui-hide" id="demo1">
                        <button type="button" class="layui-btn layui-btn-normal" id="test8">选择文件</button>
                        <button type="button" class="layui-btn" id="test9">开始上传</button>
                    </div>
                    <input type="text" name="coupon_img" id="coupon_img_add" autocomplete="off"
                           class="layui-input layui-hide">
                </div>
            </div>
            <!--            <div class="layui-inline">-->
            <!--                <label class="layui-form-label">优惠码</label>-->
            <!--                <div class="layui-input-block">-->
            <!--                    <input type="text" name="code"  autocomplete="off" class="layui-input">-->
            <!--                </div>-->
            <!--            </div>-->
        </div>

        <div style="margin-top: 25px" class="layui-form-item layui-form-text">
            <label class="layui-form-label">备注</label>
            <div class="layui-input-block">
                <textarea name="note" placeholder="请输入内容备注" class="layui-textarea"></textarea>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button type="button" class="layui-btn" id="couponUp" lay-submit="" lay-filter="couponUp">立即提交
                </button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
</div>


<!-- 优惠卷分类的关联关系维护--------------------------------------------------->
<div style="display: none" id="coupon_category_div">
    <!--  优惠减关联分类的条件搜索区域-->
    <form style="margin-top: 20px" class="layui-form layui-form-pane">
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">优惠卷名字</label>
                <div class="layui-input-block">
                    <input type="text" name="coupon_name" id="coupon_category_name_sousou" autocomplete="off"
                           class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <div class="layui-input-inline">
                    <button type="button" class="layui-btn" id="coupon_category_couponSusuo" lay-filter="couponSusuo">
                        搜索
                    </button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </div>
        </div>
    </form>
    <!--优惠卷分类的表格显示渲染-->
    <table id="coupon_category_demo" lay-filter="coupon_category_test"></table>
</div>

<!--优惠卷分类维护关系侧边栏-->
<script type="text/html" id="coupon_category_barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="coupon_category_edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="coupon_category_del">删除</a>
</script>

<!--优惠卷分类维护关系头部工具栏-->
<script type="text/html" id="coupon_category_toolbarDemo">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" id="coupon_category_add_tree" lay-event="add">添加</button>
        <button class="layui-btn layui-btn-sm" lay-event="delete">删除</button>
    </div>
</script>

<!--优惠卷分类维护添加功能-->
<div style="display:none" id="coupon_category_add_div">
    <form class="layui-form" id="coupon_category_add_form" lay-filter="coupon_category_add_form" action="">
        <div class="layui-form-item">
            <label class="layui-form-label">分类</label>
            <div class="layui-input-block">
                <ul id="add_selTree4" class="dtree" data-id="0"></ul>
            </div>
            <input type="text" name="category_id" id="category_id_add" class="layui-input layui-hide">
            <input type="text" name="category_name" id="category_name_add" class="layui-input layui-hide">
            <input type="text" name="coupon_id" id="coupon_id_add" class="layui-input layui-hide">
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit id="coupon_category_btn_add" lay-filter="coupon_category_btn_add">
                    立即提交
                </button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
</div>

<!--优惠卷分类维护修改功能-->
<div style="display:none" id="coupon_category_up_div">
    <form class="layui-form" id="coupon_category_up_form" lay-filter="coupon_category_up_form" action="">
        <div class="layui-form-item">
            <label class="layui-form-label">分类</label>
            <div class="layui-input-block">
                <ul id="up_selTree4" class="dtree" data-value="" data-id="0"></ul>
            </div>
            <input type="text" name="category_id" id="category_id_up" class="layui-input layui-hide">
            <input type="text" name="category_name" id="category_name_up" class="layui-input layui-hide">
            <input type="text" name="coupon_id" id="coupon_id_up" class="layui-input layui-hide">
            <input type="text" name="id" class="layui-input layui-hide">
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit id="coupon_category_btn_up" lay-filter="coupon_category_btn_up">
                    立即提交
                </button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
</div>

<!--显示图片信息-->
<script type="text/html" id="imgTpl">
    <img style="max-height: 100%; max-width: 100%;" onclick="showBigImage(this)" src={{ d.coupon_img }}>
</script>

<script>
    layui.extend({
        dtree: '../static/layui_ext/dtree/dtree/',   // {/}的意思即代表采用自有路径，即不跟随 base 路径
        numinput: '../static/modules/numinput/numinput'
    }).use(['form', 'table', 'laydate', 'layer', 'dtree', 'numinput', 'upload'], function () {
        let $ = layui.$;
        let form = layui.form;
        let table = layui.table;
        let laydate = layui.laydate;
        let layer = layui.layer;
        let dtree = layui.dtree;
        let numinput = layui.numinput;
        let upload = layui.upload;


        //执行一个 table 实例
        table.render({
            elem: '#coupondemo'
            , url: glodate.serverZuul + 'coupon/find_admin_coupon_All' //数据接口
            , toolbar: '#toolbarDemo' //开启工具栏，此处显示默认图标，可以自定义模板，详见文档
            , page: true //开启分页
            , cols: [[ //表头
                {type: 'checkbox', style: 'height:100px;', fixed: 'left'}
                , {type: 'numbers', style: 'height:100px;', title: '序号', fixed: 'left'}
                , {field: 'coupon_name', title: '优惠卷名字'}
                , {
                    field: 'coupon_img', title: '图片',
                    style: 'height:100px;', width: '6%',
                    templet: '#imgTpl'
                }
                , {
                    field: 'coupon_type', title: '优惠卷类型', templet:

                        function (d) {
                            if (d.coupon_type == 0) {
                                return '<span class="layui-badge-rim">全场赠券</span>'
                            } else if (d.coupon_type == 1) {
                                return '<span class="layui-badge layui-bg-orange">会员赠券</span>'
                            } else if (d.coupon_type == 2) {
                                return '<span class="layui-badge layui-bg-gray">购物赠券</span>'
                            } else if (d.coupon_type == 3) {
                                return '<span class="layui-badge layui-bg-blue">注册赠券</span>'
                            }
                        }
                } //优惠卷类型[0->全场赠券；1->会员赠券；2->购物赠券；3->注册赠券]',
                ,
                {
                    field: 'member_level', title: '会员等级', templet: function (d) {
                        if (d.member_level == 0) {
                            return '<span class="layui-badge-rim">不限等级</span>'
                        } else {
                            return '<span class="layui-badge layui-bg-orange">对应等级</span>'
                        }
                    }
                }//可以领取的会员等级[0->不限等级，其他-对应等级]'
                , {field: 'enable_start_time', title: '领取的开始日期'}
                , {field: 'enable_end_time', title: '领取的结束日期'}
                , {
                    field: 'use_type', title: '使用类型', templet: function (d) {
                        if (d.use_type == 0) {
                            return '<span class="layui-badge-rim">全场通用</span>'
                        } else if (d.use_type == 1) {
                            return '<span class="layui-badge layui-bg-orange">指定分类</span>'
                        } else {
                            return '<span class="layui-badge layui-bg-gray">指定商品</span>'
                        }
                    }
                }//使用类型[0->全场通用；1->指定分类；2->指定商品]'
                , {
                    field: 'publish', title: '发布状态', templet: function (d) {
                        if (d.use_type == '已发布') {
                            return '<span class="layui-badge-rim">已发布</span>'
                        } else {
                            return '<span class="layui-badge layui-bg-orange">未发布</span>'
                        }
                    }
                } //0已发布  1未发布
                , {fixed: 'right', width: 250, align: 'center', toolbar: '#barDemo'}
            ]],
            id: "coupontableId"
        });

        //优惠卷的搜索
        $("#couponSusuo").on('click', function () {
            active.reload();
            return false
        });

        active = {
            reload: function () {
                //上述方法等价于
                table.reload('coupontableId', {
                    where: { //设定异步数据接口的额外参数，任意设
                        'coupon_name': $("#coupon_name_sousou").val()
                    }
                    , page: {
                        curr: 1 //重新从第 1 页开始
                    }
                }); //只重载数据
            }
        }


        //优惠卷头部监听事件
        table.on('toolbar(coupontest)', function (obj) {
            var checkStatus = table.checkStatus('coupontableId');
            data = checkStatus.data;
            switch (obj.event) {
                case 'add':
                    layer.open({
                        type: 2,
                        skin: 'demo-class',
                        area: ['700px', '500px'],
                        anim: 5,
                        fixed: false,
                        content: 'couponadd.html', //这里content是一个普通的String
                        btn: ['关闭'],
                        yes: function (index, layero) {
                            layer.close(index);
                        }
                    });
                    return false;
                    break;
                case 'delete':
                    if (data.length == 0) {
                        layer.msg('请选者数据');
                    } else {
                        let coupon_id = [];
                        for (let i = 0; i < data.length; i++) {
                            coupon_id.push(data[i].id);
                        }
                        let ids = coupon_id.join(",");
                        console.log(ids);
                        layer.confirm("确认删除这[" + data.length + "]条数据吗？", function () {
                            $.ajax({
                                url: glodate.serverZuul + "coupon/delete_admin_coupon_All",
                                method: "delete",
                                data: {"id": ids},
                                success: function (res) {
                                    console.log(res);
                                    if (res.code == 200) {
                                        layer.msg("删除成功！", {icon: 6});
                                    } else {
                                        layer.alert(res.msg, {icon: 5})
                                    }
                                }
                            })
                            active.reload();
                        });

                    }
                    break;
            }
            ;
        });

        //优惠卷的侧边栏监听事件
        table.on('tool(coupontest)', function (obj) { //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
            let data = obj.data; //获得当前行数据
            let layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
            let tr = obj.tr; //获得当前行 tr 的 DOM 对象（如果有的话）
            if (layEvent === 'coupon_category_relation') {
                layer.open({
                    type: 1,
                    skin: 'demo-class',
                    area: ['700px', '500px'],
                    anim: 5,
                    fixed: false,
                    content: $("#coupon_category_div"), //这里content是一个普通的String
                    btn: ['关闭'],
                    yes: function (index, layero) {
                        layer.close(index);
                    }
                });

                //渲染优惠卷分类的表格显示
                table.render({
                    elem: '#coupon_category_demo'
                    , url: glodate.serverZuul + 'sms_coupon_category/find_admin_sms_coupon_category' //数据接口
                    , page: true //开启分页
                    , where: {
                        'coupon_id': data.id
                    }
                    , toolbar: '#coupon_category_toolbarDemo' //开启工具栏，此处显示默认图标，可以自定义模板，详见文档
                    , cols: [[ //表头
                        {type: 'checkbox', fixed: 'left'}
                        , {type: 'numbers', title: '序号', fixed: 'left'}
                        , {field: 'category_name', title: '分类名称'}
                        , {fixed: 'right', width: 165, align: 'center', toolbar: '#coupon_category_barDemo'}
                    ]], id: 'coupon_category_tableId'
                });
                //优惠卷分类的关联 维护关系
                $("#coupon_category_couponSusuo").on('click', function () {
                    coupon_category_active.reload();
                    return false;
                })

                coupon_category_active = {
                    reload: function () {
                        table.reload('coupon_category_tableId', {
                            where: { //设定异步数据接口的额外参数，任意设
                                'category_name': $("#coupon_category_name_sousou").val()
                            }
                            , page: {
                                curr: 1 //重新从第 1 页开始
                            }
                        }); //只重载数据
                    }
                }

                let coupon_category_add_open;
                //优惠卷关联关系头部工具栏事件
                table.on('toolbar(coupon_category_test)', function (obj) {
                    let checkStatus = table.checkStatus("coupon_category_tableId");//监听table表格事件点击
                    let data = checkStatus.data;
                    switch (obj.event) {
                        case 'add':
                            coupon_category_add_open = layer.open({
                                type: 1,
                                skin: 'demo-class',
                                area: ['500px', '400px'],
                                anim: 5,
                                fixed: false,
                                content: $("#coupon_category_add_div"), //这里content是一个普通的String
                                btn: ['关闭'],
                                yes: function (index, layero) {
                                    // 重置清空
                                    layer.close(index);
                                }
                            });
                            //重新加载树的渲染方法
                            dtree.reload("add_selTree4", {
                                url: glodate.serverZuul + 'category/getTree',
                            });
                            return false;
                            break;
                        case 'delete':  //优惠卷分类的维护多删
                            if (data.length == 0) {
                                layer.msg('请选者数据');
                            } else {
                                let coupon_category_id = [];
                                for (let i = 0; i < data.length; i++) {
                                    coupon_category_id.push(data[i].id);
                                }
                                let ids = coupon_category_id.join(",");
                                console.log(ids);
                                layer.confirm("确认删除这[" + data.length + "]条数据吗？", function () {
                                    $.ajax({
                                        url: glodate.serverZuul + "sms_coupon_category/del_admin_sms_coupon_category",
                                        method: "delete",
                                        data: {"id": ids},
                                        success: function (res) {
                                            console.log(res);
                                            if (res.code == 200) {
                                                layer.msg("删除成功！", {icon: 6});
                                            } else {
                                                layer.alert(res.msg, {icon: 5})
                                            }
                                        }
                                    })
                                    coupon_category_active.reload();
                                });

                            }
                            break;
                    }
                    ;
                });

                //新增
                form.on('submit(coupon_category_btn_add)', function () {
                    let datas = form.val('coupon_category_add_form');
                    datas.coupon_id = data.id;
                    console.log(data);
                    $.ajax({
                        url: glodate.serverZuul + "sms_coupon_category/insert_admin_sms_coupon_category",
                        type: "post",
                        data: datas,
                        dataType: "json",
                        success: function (res) {
                            console.log(res);
                            if (res.code == 200) {
                                layer.msg("添加成功", {icon: 6});
                                formIdreset("#coupon_category_add_form");//重置表单的初始内容
                                layer.close(coupon_category_add_open);
                            } else {
                                layer.msg(res.msg, {icon: 5});
                            }
                            coupon_category_active.reload();
                        }
                    })
                    return false;
                })


                //监听优惠卷分类关联信息侧边工具栏
                table.on('tool(coupon_category_test)', function (obj) { //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
                    let data = obj.data; //获得当前行数据
                    let layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
                    let tr = obj.tr; //获得当前行 tr 的 DOM 对象（如果有的话）
                    if (layEvent === 'coupon_category_del') { //删除
                        layer.confirm('您确认删除[' + data.category_name + ']吗?', function (index) {
                            $.ajax({
                                url: glodate.serverZuul + "sms_coupon_category/del_admin_sms_coupon_category",
                                type: "delete",
                                data: {"id": data.id},
                                dataType: "json",
                                success: function (res) {
                                    console.log(res)
                                    if (res.code == 200) {
                                        layer.msg("删除成功", {icon: 6});
                                    } else {
                                        layer.msg(res.msg, {icon: 5});
                                    }
                                    coupon_category_active.reload();
                                }
                            })
                        });
                    } else if (layEvent === 'coupon_category_edit') { //编辑
                        form.val('coupon_category_up_form', data)
                        $("#up_selTree4").attr("data-value", data.category_id);
                        layer.open({
                            type: 1,
                            skin: 'demo-class',
                            area: ['500px', '300px'],
                            anim: 5,
                            fixed: false,
                            content: $("#coupon_category_up_div"), //这里content是一个普通的String
                            btn: ['关闭'],
                            yes: function (index, layero) {
                                layer.close(index);
                            }
                        });
                        //重新加载树的渲染方法
                        dtree.reload("up_selTree4", {
                            url: glodate.serverZuul + 'category/getTree',
                            selectInitVal: data.category_id
                        });
                        return false;
                    }
                });

                //优惠卷分类的修改操作
                form.on('submit(coupon_category_btn_up)', function () {
                    let datas = form.val('coupon_category_up_form');
                    $.ajax({
                        url: glodate.serverZuul + "sms_coupon_category/up_admin_sms_coupon_category",
                        type: "put",
                        data: datas,
                        dataType: "json",
                        success: function (res) {
                            console.log(res)
                            if (res.code == 200) {
                                layer.msg("修改成功", {icon: 6})
                            } else {
                                layer.msg(res.msg, {icon: 5});
                            }
                            coupon_category_active.reload();
                        }
                    })
                    return false;
                })


            } else if (layEvent === 'detail') { //查看
                form.val('', data);
                layer.open({
                    type: 2,
                    skin: 'demo-class',
                    area: ['700px', '500px'],
                    anim: 5,
                    fixed: false,
                    content: 'couponadd.html', //这里content是一个普通的String
                    btn: ['关闭'],
                    yes: function (index, layero) {
                        layer.close(index);
                    }
                });
                return false;
            } else if (layEvent === 'del') { //删除
                layer.confirm('您确认删除[' + data.category_name + ']数据吗?', function (index) {
                    $.ajax({
                        url: glodate.serverZuul + "coupon/delete_admin_coupon_All",
                        method: "delete",
                        data: {"id": data.id},
                        success: function (res) {
                            console.log(res);
                            if (res.code == 200) {
                                layer.msg("删除成功！", {icon: 6});
                            } else {
                                layer.alert(res.msg, {icon: 5})
                            }
                        }
                    })
                    active.reload();
                });
            } else if (layEvent === 'edit') { //编辑
                form.val('couponUpForm', data);
                $("#demo1").attr("src", data.coupon_img);//回显图片信息的绑定
                console.log(data.coupon_img)

                layer.open({
                    type: 1,
                    skin: 'demo-class',
                    area: ['800px', '500px'],
                    anim: 5,
                    content: $("#couponDiv"),
                    btn: ['关闭'],
                    yes: function (index, layero) {
                        layer.close(index);
                    }
                });
                return false;
            }
        });

        //优惠卷的修改操作
        form.on('submit(couponUp)', function () {
            let datas = form.val('couponUpForm');
            $.ajax({
                url: glodate.serverZuul + "coupon/up_admin_coupon_All",
                type: "put",
                data: datas,
                dataType: "json",
                success: function (res) {
                    console.log(res)
                    if (res.code == 200) {
                        layer.msg("修改成功", {icon: 6})
                    } else {
                        layer.msg(res.msg, {icon: 5});
                    }
                }
            })
            active.reload();
            layer.closeAll();
            return false;
        })


        //优惠卷与分类的新增下拉单树关联关系
        dtree.renderSelect({
            elem: "#add_selTree4",
            width: "100%", // 指定树的宽度
            method: "get",
            async: false,
            selectTips: "单选数据示例",
            menubar: true, //开启菜单栏
            dataStyle: "layuiStyle",  //使用layui风格的数据格式
            response: {message: "msg", statusCode: 0}, //修改response中返回数据的定义
            url: glodate.serverZuul + 'category/getTree', // 使用url加载（可与data加载同时存在）
            selectTips: "请选择",
            selectInputName: {  //指定下拉树获取的表单名称
                nodeId: "nodeId",
                context: "context"
            }
        });
        //优惠卷与分类的新增获取值下拉单树关联关系
        dtree.on('node(add_selTree4)', function (obj) {
            let param = dtree.selectVal("add_selTree4");
            $("#category_id_add").val(param["nodeId"]);//获取ID
            $("#category_name_add").val(param["context"]);//获取名称
            console.log(param["nodeId"]);
            console.log(param["context"]);
            layer.msg(JSON.stringify(param));
        });


        //优惠卷与分类的修改下拉单树关联关系    修改
        dtree.renderSelect({
            elem: "#up_selTree4",
            width: "100%", // 指定树的宽度
            method: "get",
            async: false,
            selectTips: "单选数据示例",
            menubar: true, //开启菜单栏
            dataStyle: "layuiStyle",  //使用layui风格的数据格式
            response: {message: "msg", statusCode: 0}, //修改response中返回数据的定义
            url: glodate.serverZuul + 'category/getTree', // 使用url加载（可与data加载同时存在）
            selectTips: "请选择",
            selectInputName: {  //指定下拉树获取的表单名称
                nodeId: "nodeId",
                context: "context"
            }
        });
        //优惠卷与分类的修改获取值下拉单树关联关系      修改
        dtree.on('node(up_selTree4)', function (obj) {
            let param = dtree.selectVal("up_selTree4");
            $("#category_id_up").val(param["nodeId"]);//获取ID
            $("#category_name_up").val(param["context"]);//获取名称
            console.log(param["nodeId"]);
            console.log(param["context"]);
            layer.msg(JSON.stringify(param));
        });


        //选完文件后不自动上传
        upload.render({
            elem: '#test8'
            , url: glodate.serverZuul + 'brand/filesUploadLayui'//我的上传接口 //改成您自己的上传接口
            , auto: false
            , bindAction: '#test9'
            , choose: function (obj) {
                //预读本地文件示例，不支持ie8
                obj.preview(function (index, file, result) {
                    $('#demo1').attr('src', result); //图片链接（base64）
                    $("#demo1").removeClass("layui-hide");
                });
            }
            , done: function (res, index, upload) {
                console.log(res);
                //假设code=0代表上传成功
                if (res.code == 0) {
                    $("#coupon_img_add").val(res.data);

                    //do something （比如将res返回的图片链接保存到表单的隐藏域）
                    layer.msg(res.msg, {icon: 1});
                }
            }, error: function (index, upload) {
                //当上传失败时，你可以生成一个“重新上传”的按钮，点击该按钮时，执行 upload() 方法即可实现重新上传
            }
        });


        //数量框的渲染
        numinput.init({
            // 123：123键置顶, 789：789键置顶
            topBtns: 123,
            // 右侧功能按钮
            rightBtns: true,
            // 监听键盘事件
            listening: true,
            // 批量配置默认小数精确度
            // defaultPrec: ''
        });


        //点击图片放大
        window.showBigImage = function (e) {
            //此处放置函数内容
            layer.open({
                type: 1,
                title: false,
                closeBtn: 0,
                shadeClose: true, //点击阴影关闭
                area: [$(e).width + 'px', $(e).height + 'px'], //宽高
                content: "<img src=" + $(e).attr('src') + " />"
            });
        }



        //将日期直接嵌套在指定容器中
        laydate.render({
            elem: '#start_time'
            , type: 'datetime'
            , trigger: 'click'
            ,min: 0
            ,max: 7
            ,theme: 'molv'
        });
        laydate.render({
            elem: '#end_time'
            , type: 'datetime'
            , trigger: 'click'
            ,min: 0
            ,max: 7
            ,theme: 'molv'
        });
        laydate.render({
            elem: '#enable_start_time'
            , type: 'datetime'
            , trigger: 'click'
            ,min: 0
            ,max: 7
            ,theme: 'molv'
        });
        laydate.render({
            elem: '#enable_end_time'
            , type: 'datetime'
            , trigger: 'click'
            ,min: 0
            ,max: 7
            ,theme: 'molv'
        });

        //提取的清楚表單的方法  formId form表头的id值
        function formIdreset(formId) {
            // 重置清空
            $(formId)[0].reset();
            form.render();//必须写
        }

    });
</script>

</body>
</html>